/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Handler for routing packets between multiple hubs - header.
 * \author Antti Maula <antti.maula@tkk.fi>
 *
 */
#ifndef _ROUTING_H_
#define _ROUTING_H_
#include "connection.h"
#include "idmap.h"
#include <inttypes.h>

#define MAX_ROUTING_ENTRIES 65536

#define ROUTINGTABLE_ADDR_LOCAL 0

#define ROUTING_OK              0
#define ROUTING_ERROR           -1


typedef struct SRoutingEntry
{
  uint32_t target_id;   ///< Packet destination address.
  uint32_t gateway_id;  ///< Gateway in local link.
  uint32_t distance;    ///< Hops to final destination
} TRoutingEntry;

typedef struct SRouting
{
  // IDMap storage.
  TIDMap routingmap;
  
  // DefaultGW, used when no entry from routingmap is found.
  unsigned int default_gw;
} TRouting;

/** Init preallocated module.
 *
 */
int routingInit(uint32_t default_gw);

/** DeInit module.
 *
 */
void routingDeinit(void);


/** Assign default GW.
 *
 */
void routingSetDefaultGW(uint32_t default_gw);


/** Get route by ID.
 *
 * @param[in] hubID             ID to query for in FQ format.
 *                              The search is commited as-is,
 *                              so any ID can be used for routing.
 *
 */
unsigned int routingGetRoute(uint32_t hubID);


/** Register a route for a specific hubID.
 *
 */
int routingSetRoute(uint32_t hubID, uint32_t gatewayID);

#endif //_ROUTING_H_
